package offer_test_40;

import struct.MyStack;



//定义栈的数据结构，请在该类型中实现一个能够得到栈的最小元素的min函数。
//在该栈中，调用min、push及pop德尔时间复杂度都是O(1)
public class one_MinInStack {
	public MyStack dataStack=new MyStack(100);
	public MyStack minStack=new MyStack(100);

	public static void main(String[] args) {
		one_MinInStack test=new one_MinInStack();
		test.push(3);
		test.push(2);
		test.push(100);
		test.push(4);
		test.push(5);
		System.out.println(test.min());
	}

	public one_MinInStack() {
	}

	public Integer pop() {
		if(dataStack.elementCount==0||minStack.elementCount==0){
			return null;
		}
		minStack.pop();
		return (Integer)dataStack.pop();
	}

	public Integer min() {
		if(minStack.elementCount==0)
			return null;
			return (Integer)minStack.peak();
	}

	public void push(Integer input) {
		dataStack.push(input);
		if(minStack.elementCount==0||input<=(int)minStack.peak()){
			minStack.push(input);
		}else{
			minStack.push(minStack.peak());
		}
	}
}
